package cn.tedu.ivos.repair.service.impl;

import cn.tedu.ivos.repair.mapper.RepairMapper;
import cn.tedu.ivos.repair.pojo.dto.RepairQuery;
import cn.tedu.ivos.repair.pojo.dto.RepairSaveParam;
import cn.tedu.ivos.repair.pojo.entity.Repair;
import cn.tedu.ivos.repair.pojo.vo.RepairVO;
import cn.tedu.ivos.repair.service.RepairService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class RepairServiceImpl implements RepairService {
    @Autowired
    private RepairMapper repairMapper;
    @Override
    public List<RepairVO> selectRepair(RepairQuery repairQuery) {
        log.debug("车辆维修查询业务,参数:{}",repairQuery);
        List<RepairVO> list = repairMapper.selectRepair(repairQuery);
        //log.debug("查询结果:{}",list);
        return list;
    }

    @Override
    public void saveRepair(RepairSaveParam repairSaveParam) {
        log.debug("车辆维修保存业务,参数:{}",repairSaveParam);
        Repair repair = new Repair();
        BeanUtils.copyProperties(repairSaveParam,repair);
        if (repair.getId()==null){
            log.debug("新增,参数:"+repair);
            repair.setCreateTime(new Date());
            repairMapper.insert(repair);
        }else {
            log.debug("修改,参数:"+repair);
            repair.setUpdateTime(new Date());
            repairMapper.update(repair);
        }
    }

    @Override
    public void delete(Long id) {
        log.debug("车辆维修删除业务,参数:{}",id);
        repairMapper.delete(id);
    }
}
